class HumbleSitesController < ApplicationController
  before_action :set_humble_site, only: [:show, :edit, :update, :destroy]
  before_filter :find_personas, :only => [:create, :edit, :update]

  respond_to :html

  def index
    @humble_sites = HumbleSite.all
    respond_with(@humble_sites)
  end

  def show
    respond_with(@humble_site)
  end

  def new
    @humble_site = HumbleSite.new
    respond_with(@humble_site)
  end

  def edit
  end

  def create
    @humble_site = HumbleSite.new(humble_site_params)
    @humble_site.save
    respond_with(@humble_site)
  end

  def update
    @humble_site.update(humble_site_params)
    respond_with(@humble_site)
  end

  def destroy
    @humble_site.destroy
    respond_with(@humble_site)
  end

  private
    def set_humble_site
      @humble_site = HumbleSite.find(params[:id])
    end

    def humble_site_params
      params.require(:humble_site).permit(:user_id, :user_confirm_id, :url, :properties, :ax_fetch, :sreg)
    end
    
    def site
      @site ||= current_user.humble_site.find(params[:id])
    end

    def persona
      @user_confirm ||= site.user_confirm
    end

    def find_personas
      @user_confirms = current_user.personas.order(:title)
    end
end
